//
//  EquipmenDetailsViewModel.m
//  DataStatistics
//
//  Created by Kang on 15/12/30.
//  Copyright © 2015年 YTYangK. All rights reserved.
//

#import "EquipmenDetailsViewModel.h"
#import "DeviceDetailsModel.h"  //设备详情模型
#import "DeviceBindingModel.h"   // 添加设备模型

@interface EquipmenDetailsViewModel()
@end


@implementation EquipmenDetailsViewModel
singleton_for_implementation(EquipmenDetailsViewModel)


#pragma mark - 扫描设备的详情信息
+ (void)requestWithUrlForDeviceDetails:(id)obj andParam:(NSDictionary *)param
                               success:(void(^)(DeviceDetailsModel *model))success failure:(void(^)(NSString * error))failure {
    //__weak typeof (ViewModelClass *) weakSuper = [ViewModelClass sharedViewModelClss];
    
    
       [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    [NetRequestClss requestWithUrl:@"/app/scanDevice.do" requestWithParameters:param method:NetMethodGET returnSuccess:^(id objs, int status, NSString *mag) {
        
        DeviceDetailsModel *listModel = [DeviceDetailsModel mj_objectWithKeyValues:objs];
        
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

        
        
            if ([objs[@"result"] isEqualToString:@"success"]) {
                
                success(listModel);
                return;
            }else{
            
                [MBProgressHUD yty_showErrorWithTitle:nil detailsText:objs[@"msg"] toView:nil];
                

        }
        
    } returnError:^(NSString *err) {
        failure(err);
    }];
}


#pragma mark - 添加绑定修改昵称
+ (void)requestWithUrlForDeviceBinding:(id)obj andParam:(NSDictionary *)param
                               success:(void(^)(id model))success failure:(void(^)(NSString * error))failure {
    NSMutableDictionary *mutDic = [[NSMutableDictionary alloc] init];
    NSString *halfPathUrl = [param objectForKey:@"querDetailList"];
    
    
    
    if (halfPathUrl == nil) {
        halfPathUrl = @"/app/bindDevice.do";
        [mutDic setDictionary:param];
    }    else {
        halfPathUrl = [NSString stringWithFormat:@"deviceList/%@",halfPathUrl];
        [mutDic setObject:[param objectForKey:@"deviceNo"] forKey:@"deviceNo"];
        [mutDic setObject:[param objectForKey:@"nickname"] forKey:@"nickname"];
    }
    MDC_INTER_DIC(halfPathUrl, @"NetMethodPOST", @"false")
    
    [super initRequestWithUrlObj:obj parametersDic:param Interface:inter success:^(id obj, id model) {
    

        if ([[model objectForKey:@"result"] isEqualToString:@"success"]) {
                success(model);

            }else {
                
                [MBProgressHUD yty_showErrorWithTitle:nil detailsText:[model objectForKey:@"msg"] toView:nil];
            }
        
    } failure:^(id obj, NSString *err) {
          failure(err); //返回是因为需要列表拉下来
    }];

    
    
}


+ (void)requestWithUrlForDeviceName:(id)obj andParam:(NSDictionary *)param
                            success:(void(^)(id model))success failure:(void(^)(NSString * error))failure{

        [NetRequestClss requestWithUrl:@"/app/changeDeviceName.do" requestWithParameters:param method:NetMethodPOST returnSuccess:^(id objs, int status, NSString *mag) {
            
                        
            if ([objs[@"result"]isEqualToString:@"success"]) {
                success(objs[@"result"]);

            }else{
                failure(objs[@"msg"]);
            }
            
        } returnError:^(NSString *err) {
            
        }];
    


}









@end
